//
//  YCScanViewController.m
//  DemoZBar
//
//  Created by 唐可雄 on 16/8/24.
//  Copyright © 2016年 swustyc. All rights reserved.
//

#import "YCScanViewController.h"

@interface YCScanViewController () <ZBarReaderViewDelegate>

@property (nonatomic) ZBarCameraSimulator *cameraSim;

@end

@implementation YCScanViewController

#pragma mark - Life Cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.readerView.readerDelegate = self;
    
    if(TARGET_IPHONE_SIMULATOR) {
        self.cameraSim = [[ZBarCameraSimulator alloc] initWithViewController: self];
        self.cameraSim.readerView = self.readerView;
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [self.readerView start];
}

- (void)viewDidDisappear:(BOOL)animated {
    [self.readerView stop];
}
- (IBAction)scanBtnDidClick:(id)sender {
}

- (void)dealloc {
    self.readerView = nil;
    self.cameraSim = nil;
}

#pragma mark - ZBarReaderViewDelegate

- (void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image {
    for(ZBarSymbol *sym in symbols) {
        self.resultTxtView.text = sym.data;
        break;
    }
}

@end
